<template>
  <div>
    <el-form :inline="true" :label-width="'110px'" :model="formModel">
      <el-form-item
        v-for="item in formList"
        :label="item.label"
        :key="item.label"
      >
        <el-select v-if="item.type === 'select'" v-model="formModel[item.prop]">
          <el-option
            v-for="op in item.options"
            :key="op.label"
            :label="op.label"
            :value="op.value"
          ></el-option>
        </el-select>
        <input
          v-else
          size="mini"
          @input="inputNative"
          type="primary"
          v-model.number="formModel[item.prop]"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="search">搜索</el-button>
        <el-button type="primary" size="mini" @click="add">添加</el-button>
      </el-form-item>
    </el-form>
    <BaseTable :data="data" :config="config"></BaseTable>
    <Dialog ref="dialog" :data="dialogData" />
    <AddDialog :show.sync="listShow" />

    <!-- <v-checkbox @click.native="singleClick" v-model="count"></v-checkbox>
    <v-input v-model="count"></v-input>
    <p>{{ count }}</p> -->
  </div>
</template>

<script>
import Dialog from "./dialog.vue";
import AddDialog from "./listDialog.vue";
import BaseTable from "./baseTable.vue";
// import VCheckbox from "./VCheckbox.vue";
// import VInput from "./VInput.vue";
export default {
  name: "detail",
  components: {
    Dialog,
    AddDialog,
    BaseTable,
    // VCheckbox,
    // VInput,
  },
  data() {
    return {
      show: false,
      listShow: false,
      dialogData: {},
      data: [
        { name: "jack", age: 10 },
        { name: "tom", age: 10 },
      ],
      config: [
        { label: "姓名", prop: "name" },
        { label: "年龄", prop: "age" },
      ],
      formList: [
        { label: "姓名", prop: "name" },
        { label: "年龄", prop: "age" },
      ],
      formModel: {
        name: "",
        age: "",
      },
      tableData: [],
      tabeConfig: {},
      count: true,
    };
  },
  mounted() {
    // this.getData();
  },
  methods: {
    singleClick(e) {
      console.log(e.target.checked);
    },
    search() {},
    add() {
      this.dialogData = {
        height: 10,
        weight: 100,
        template: [
          { class: "2班", bobby: "游泳" },
          { class: "1班", bobby: "划水" },
        ],
      };
      this.listShow = true;
      //   this.$refs.dialog.showDialog();
    },
    getData() {
      const vm = this;
      setTimeout(() => {
        vm.tableData = [
          {
            name: "jack",
            age: 11,
          },
          {
            name: "tom",
            age: 12,
          },
        ];
      });
    },
    inputNative(e) {
      e.target.value = e.target.value.replace(/(^\s*)|(\s*$)/g, "");
      const reg = /[^\d.]/g;

      // 只能是数字和小数点，不能是其他输入
      e.target.value = e.target.value.replace(reg, "");

      // 保证第一位只能是数字，不能是点
      e.target.value = e.target.value.replace(/^\./g, "");
      // 小数只能出现1位
      e.target.value = e.target.value
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".");
      // 小数点后面保留2位
      e.target.value = e.target.value.replace(
        /^(-)*(\d+)\.(\d\d).*$/,
        "$1$2.$3"
      );
    },
    input(e) {
      console.log(e);
    },
  },
};
</script>

<style lang="scss" scoped></style>
